From 3d0f882e8409422d3764de080c3326e384095fba Mon Sep 17 00:00:00 2001 From: oliskoli Date: Fri, 5 May 2006 20:35:48 +0000 Subject: [PATCH] Use macros DEG() and RAD(), defined in grtcirc.h, for conversions between degrees and radians. --- arcdist.c | 6 +++--- copilot.c | 12 +++++------- coto.c | 13 +++++++------ csv_util.c | 4 ++-- grtcirc.c | 15 ++++++++------- grtcirc.h | 6 ++++++ interpolate.c | 8 ++++---- overlay.c | 12 ++++++------ position.c | 8 ++++---- psp.c | 9 +++++---- saroute.c | 6 +++--- vitosmt.c | 9 +++++---- 12 files changed, 58 insertions(+), 50 deletions(-) diff --git a/arcdist.c b/arcdist.c index 52a34fb0c..cbb8ced95 100644 --- a/arcdist.c +++ b/arcdist.c @@ -99,9 +99,9 @@ arcdist_process(void) } if ( ed->distance == BADVAL || ed->distance >= pos_dist ) { if ( ptsopt ) { - dist = gcdist( lat2*M_PI/180.0, lon2*M_PI/180.0, - waypointp->latitude*M_PI/180.0, - waypointp->longitude*M_PI/180.0 ); + dist = gcdist( RAD(lat2), RAD(lon2), + RAD(waypointp->latitude), + RAD(waypointp->longitude) ); } else { dist = linedist(lat1, lon1, lat2, lon2, diff --git a/copilot.c b/copilot.c index c2828fdad..879d49a9b 100644 --- a/copilot.c +++ b/copilot.c @@ -22,8 +22,7 @@ #include "defs.h" #include "coldsync/palm.h" #include "coldsync/pdb.h" - -static double conv = 180.0 / M_PI; +#include "grtcirc.h" #define MYNAME "CoPilot Waypoint" #define MYTYPE 0x77617970 /* wayp */ @@ -92,9 +91,9 @@ data_read(void) rec = (struct record *) pdb_rec->data; wpt_tmp->longitude = - -pdb_read_double(&rec->longitude) * conv; + DEG(-pdb_read_double(&rec->longitude)); wpt_tmp->latitude = - pdb_read_double(&rec->latitude) * conv; + DEG(pdb_read_double(&rec->latitude)); wpt_tmp->altitude = pdb_read_double(&rec->elevation) * .3048; @@ -124,9 +123,8 @@ copilot_writewpt(const waypoint *wpt) rec = xcalloc(sizeof(*rec)+1141,1); - pdb_write_double(&rec->latitude, wpt->latitude / conv); - pdb_write_double(&rec->longitude, - -wpt->longitude / conv); + pdb_write_double(&rec->latitude, RAD(wpt->latitude)); + pdb_write_double(&rec->longitude, RAD(-wpt->longitude)); pdb_write_double(&rec->elevation, wpt->altitude / .3048); pdb_write_double(&rec->magvar, 0); diff --git a/coto.c b/coto.c index 3b537d06a..38e5e3ff1 100644 --- a/coto.c +++ b/coto.c @@ -28,6 +28,7 @@ #include "csv_util.h" #include "coldsync/palm.h" #include "coldsync/pdb.h" +#include "grtcirc.h" #define MYNAME "cotoGPS" @@ -194,8 +195,8 @@ coto_track_read(struct pdb *pdb) rec = (struct record_track *) pdb_rec->data; - wpt_tmp->longitude = -pdb_read_double(&rec->longitude)*360.0/(2.0*M_PI); - wpt_tmp->latitude = pdb_read_double(&rec->latitude)*360.0/(2.0*M_PI); + wpt_tmp->longitude = DEG(-pdb_read_double(&rec->longitude)); + wpt_tmp->latitude = DEG(pdb_read_double(&rec->latitude)); // It's not the course, so leave it out for now // wpt_tmp->course = pdb_read_double(&rec->arc); @@ -261,8 +262,8 @@ coto_wpt_read(struct pdb *pdb) rec = (struct record_wpt *) pdb_rec->data; - wpt_tmp->longitude = -pdb_read_double(&rec->lon)*360.0/(2.0*M_PI); - wpt_tmp->latitude = pdb_read_double(&rec->lat)*360.0/(2.0*M_PI); + wpt_tmp->longitude = DEG(-pdb_read_double(&rec->lon)); + wpt_tmp->latitude = DEG(pdb_read_double(&rec->lat)); wpt_tmp->shortname = xstrndup(rec->name, sizeof(rec->name)); @@ -379,8 +380,8 @@ coto_wpt_write(const waypoint *wpt) size += strlen(notes); rec = xcalloc(size, 1); - pdb_write_double(&rec->lon, -2.0*M_PI*wpt->longitude/360.0); - pdb_write_double(&rec->lat, 2.0*M_PI*wpt->latitude/360.0); + pdb_write_double(&rec->lon, RAD(-wpt->longitude)); + pdb_write_double(&rec->lat, RAD(wpt->latitude)); strncpy(rec->name, shortname, MAX_MARKER_NAME_LENGTH); if (notes) diff --git a/csv_util.c b/csv_util.c index be00ddb56..b1d172e5f 100644 --- a/csv_util.c +++ b/csv_util.c @@ -1083,8 +1083,8 @@ xcsv_waypt_pr(const waypoint *wpt) queue *elem, *tmp; if ( oldlon < 900 ) { - pathdist += radtomiles(gcdist(oldlat*M_PI/180,oldlon*M_PI/180, - wpt->latitude*M_PI/180,wpt->longitude*M_PI/180)); + pathdist += radtomiles(gcdist(RAD(oldlat),RAD(oldlon), + RAD(wpt->latitude),RAD(wpt->longitude))); } oldlon = wpt->longitude; oldlat = wpt->latitude; diff --git a/grtcirc.c b/grtcirc.c index 2bb40b0b2..eb72780ed 100644 --- a/grtcirc.c +++ b/grtcirc.c @@ -21,6 +21,7 @@ #include #include #include "defs.h" +#include "grtcirc.h" static const double EARTH_RAD = 6378137.0; @@ -120,9 +121,9 @@ double linedist(double lat1, double lon1, int newpoints; /* degrees to radians */ - lat1 *= M_PI/180.0; lon1 *= M_PI/180.0; - lat2 *= M_PI/180.0; lon2 *= M_PI/180.0; - lat3 *= M_PI/180.0; lon3 *= M_PI/180.0; + lat1 = RAD(lat1); lon1 = RAD(lon1); + lat2 = RAD(lat2); lon2 = RAD(lon2); + lat3 = RAD(lat3); lon3 = RAD(lon3); newpoints = 1; if ( lat1 == _lat1 && lat2 == _lat2 && lon1 == _lon1 && lon2 == _lon2) { @@ -266,8 +267,8 @@ void linepart(double lat1, double lon1, double sinphi = 0; /* degrees to radians */ - lat1 *= M_PI/180.0; lon1 *= M_PI/180.0; - lat2 *= M_PI/180.0; lon2 *= M_PI/180.0; + lat1 = RAD(lat1); lon1 = RAD(lon1); + lat2 = RAD(lat2); lon2 = RAD(lon2); /* polar to ECEF rectangular */ x1 = cos(lon1)*cos(lat1); y1 = sin(lat1); z1 = sin(lon1)*cos(lat1); @@ -313,12 +314,12 @@ void linepart(double lat1, double lon1, if ( zr > 1 ) zr = 1; if ( zr < -1 ) zr = -1; - *reslat = asin(yr) * 180 / M_PI; + *reslat = DEG(asin(yr)); if( xr == 0 && zr == 0 ) { *reslon = 0; } else { - *reslon = atan2( zr, xr ) * 180 / M_PI; + *reslon = DEG(atan2( zr, xr )); } } } diff --git a/grtcirc.h b/grtcirc.h index 1fb749e40..c50ee4591 100644 --- a/grtcirc.h +++ b/grtcirc.h @@ -18,6 +18,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ + +#ifndef GRTCIRC_H +#define GRTCIRC_H + double gcdist( double lat1, double lon1, double lat2, double lon2 ); double heading( double lat1, double lon1, double lat2, double lon2 ); @@ -36,3 +40,5 @@ void linepart(double lat1, double lon1, #define DEG(x) ((x)*180.0/M_PI) #define RAD(x) ((x)*M_PI/180.0) + +#endif diff --git a/interpolate.c b/interpolate.c index f054ae4a4..189750d3c 100644 --- a/interpolate.c +++ b/interpolate.c @@ -96,10 +96,10 @@ interpfilt_process(void) } } else if ( opt_dist ) { - rt1 = lat1 * M_PI / 180; - rn1 = lon1 * M_PI / 180; - rt2 = wpt->latitude * M_PI / 180; - rn2 = wpt->longitude * M_PI / 180; + rt1 = RAD(lat1); + rn1 = RAD(lon1); + rt2 = RAD(wpt->latitude); + rn2 = RAD(wpt->longitude); curdist = gcdist( rt1, rn1, rt2, rn2 ); curdist = radtomiles(curdist); if ( curdist > dist ) { diff --git a/overlay.c b/overlay.c index 785919ae4..fdf3a0f68 100644 --- a/overlay.c +++ b/overlay.c @@ -580,8 +580,8 @@ static void symbol_deinit(const route_head *hd) QUEUE_FOR_EACH(&(hd->waypoint_list), elem, tmp) { waypointp = (waypoint *) elem; - lat2 = waypointp->latitude *M_PI/180.0 ; - lon2 = waypointp->longitude*M_PI/180.0 ; + lat2 = RAD(waypointp->latitude); + lon2 = RAD(waypointp->longitude); if (i) { d = gcdist(lat1, lon1, lat2, lon2 ); @@ -604,8 +604,8 @@ static void symbol_deinit(const route_head *hd) while (elem!=&(hd->waypoint_list) && ddlatitude *M_PI/180.0; - lon2 = waypointp->longitude*M_PI/180.0; + lat2 = RAD(waypointp->latitude); + lon2 = RAD(waypointp->longitude); if (i) { d = gcdist(lat1, lon1, lat2, lon2 ); @@ -621,7 +621,7 @@ static void symbol_deinit(const route_head *hd) // d = acos( sin(lats)*sin(late)+cos(lats)*cos(late)*cos(lone-lons) ); dd = acos( (sin(late) - sin(lats)*cos(d))/(cos(lats)*sin(d)) ); if (lone 360.0 ? dd - 360.0 : dd; // normalizing @@ -629,7 +629,7 @@ static void symbol_deinit(const route_head *hd) /* name of route */ /* plot text at the last point of route */ govl_dir = dd; // approximated text rotation, correct value must be the azimuth in UTM - symbol_text(lon1*180.0/M_PI,lat1*180.0/M_PI,hd->rte_name,govl_group_cnt); + symbol_text(DEG(lon1),DEG(lat1),hd->rte_name,govl_group_cnt); govl_dir = 0.0; // restore } diff --git a/position.c b/position.c index 87daf7e0c..25f6f7d41 100644 --- a/position.c +++ b/position.c @@ -78,10 +78,10 @@ static double gc_distance(double lat1, double lon1, double lat2, double lon2) { return gcdist( - (lat1 * M_PI) / 180.0, - (lon1 * M_PI) / 180.0, - (lat2 * M_PI) / 180.0, - (lon2 * M_PI) / 180.0 + RAD(lat1), + RAD(lon1), + RAD(lat2), + RAD(lon2) ); } diff --git a/psp.c b/psp.c index 29973af1a..120853078 100644 --- a/psp.c +++ b/psp.c @@ -23,6 +23,7 @@ #include "defs.h" #include "cet_util.h" #include +#include "grtcirc.h" #define MYNAME "PSP" @@ -238,11 +239,11 @@ psp_read(void) /* 8 bytes - latitude in radians */ radians = psp_fread_double(psp_file_in); - lat = (radians * 180.0) / M_PI; + lat = DEG(radians); /* 8 bytes - longitude in radians */ radians = psp_fread_double(psp_file_in); - lon = (radians * 180.0) / M_PI; + lon = DEG(radians); /* since we don't know the origin of this PSP file, we use */ /* the grid byte adjust longitude, if necessary, mimicing */ @@ -356,8 +357,8 @@ psp_waypt_pr(const waypoint *wpt) } /* convert lat/long back to radians */ - lat = (wpt->latitude * M_PI) / 180.0; - lon = (wpt->longitude * M_PI) / 180.0; + lat = RAD(wpt->latitude); + lon = RAD(wpt->longitude); pindex++; le_write16(tbuf, pindex); diff --git a/saroute.c b/saroute.c index 196565f25..a93056ad3 100644 --- a/saroute.c +++ b/saroute.c @@ -367,9 +367,9 @@ my_read(void) if ( times ) { if ( !first ) { double dist = radtomiles(gcdist( - lat*M_PI/180, -lon*M_PI/180, - oldlat*M_PI/180, - -oldlon*M_PI/180 )); + RAD(lat), RAD(-lon), + RAD(oldlat), + RAD(-oldlon) )); totaldist += dist; if ( totaldist > seglen ) { totaldist = seglen; diff --git a/vitosmt.c b/vitosmt.c index 22c7d9659..3ca048651 100644 --- a/vitosmt.c +++ b/vitosmt.c @@ -26,6 +26,7 @@ #define MYNAME "vitosmt" #include "defs.h" +#include "grtcirc.h" static FILE *infile =0; static FILE *ofs =0; @@ -175,8 +176,8 @@ vitosmt_read(void) wpt_tmp = waypt_new(); - wpt_tmp->latitude =(latrad * 180) / M_PI; - wpt_tmp->longitude =(lonrad * 180) / M_PI; + wpt_tmp->latitude =DEG(latrad); + wpt_tmp->longitude =DEG(lonrad); wpt_tmp->altitude =elev; tmStruct.tm_year =timestamp[0]+100; @@ -270,9 +271,9 @@ vitosmt_waypt_pr(const waypoint *waypointp) ++count; workbuffer = xcalloc(vitosmt_datasize,1); - WriteDouble(&workbuffer[position], (M_PI*waypointp->latitude)/180 ); + WriteDouble(&workbuffer[position], RAD(waypointp->latitude) ); position += sizeof(double); - WriteDouble(&workbuffer[position], (M_PI*waypointp->longitude)/180 ); + WriteDouble(&workbuffer[position], RAD(waypointp->longitude) ); position += sizeof(double); if ( waypointp->altitude-1 > unknown_alt) WriteDouble(&workbuffer[position], waypointp->altitude ); -- 2.30.2